import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(urlPatterns = "/t1")
public class T1Servlet extends HttpServlet {

    //这里doGet和doPost做合并处理
    public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException {
        doPost(req, res);
    }
    public void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException {
        //重定向，这里可以看到响应码为302
//        res.sendRedirect("/http/hi.html");

        //假如要发给本web中的其他网站也可以写成
        //这样更加灵活，因为不用写成/http/hi.html
        String contextPath = getServletContext().getContextPath();// /http
        res.sendRedirect(contextPath + "/hi.html");
    }
}
